/**
 * @description 首页 API 路由
 * @author 刘煎蛋
 */

const router = require('koa-router')();

const { create, getHomeBlogList } = require('../../controller/blog-home');
const { loginCheck } = require('../../middlewares/loginChecks');

router.prefix('/api/blog')

router.post('/create', async ( ctx, next ) => { 
    const { content, image } = ctx.request.body;
    // const { id: userId } = ctx.session.userInfo;
    const userId = 3;
    ctx.body = await create({ userId, content, image });
})

router.get('/loadMore/:pageIndex', async ( ctx, next ) => {
    let { pageIndex } = ctx.params;
    pageIndex = parseInt(pageIndex);
    const userId = 3;
    const result = await getHomeBlogList(userId, pageIndex);
    ctx.body = result
})

module.exports = router;